import { useAxios } from '@/utils/axios'
import type { AppInfoType, VersionAddReq, VersionPageReq, VersionPublishQuery } from './types'

const request = useAxios()

// 应用列表
export const AppListApi = () => {
  return request.get({
    url: '/apps'
  })
}

// 创建应用
export const AddAppApi = (appName: string, packageName: string, plats: string[]) => {
  return request.post({
    url: '/app',
    data: { appName: appName, packageName: packageName, plats: plats }
  })
}

// 获取应用
export const GetAppApi = (appId: string) => {
  return request.get({
    url: '/app',
    params: { appId: appId }
  })
}

// 更新应用
export const UpdateAppApi = (appName: string, appId: string, plats: string[]) => {
  return request.put({
    url: '/app',
    data: { appName: appName, appId: appId, plats: plats }
  })
}

// 获取应用资料
export const GetAppInfoApi = (appId: string) => {
  return request.get({
    url: '/app/info',
    params: { appId: appId }
  })
}

// 更新应用详情
export const EditAppInfoApi = (appInfo: AppInfoType) => {
  return request.post({
    url: '/app/info',
    data: appInfo,
    headersType: 'multipart/form-data'
  })
}

// 获取审核详情
export const GetCheckInfoApi = (appId: string) => {
  return request.get({
    url: '/app/check',
    params: { appId: appId }
  })
}

// 版本列表接口
export const VersionPageApi = (query: VersionPageReq) => {
  return request.get({
    url: '/versions',
    params: query
  })
}

// 版本添加接口
export const VersionAddApi = (query: VersionAddReq) => {
  return request.post({
    url: 'version',
    data: query,
    headersType: 'multipart/form-data'
  })
}

// 可发布版本接口
export const VersionPublishApi = (appId: string) => {
  return request.get({
    url: '/versions/publish',
    params: { appId: appId }
  })
}

// 版本发布接口
export const AppPublishApi = (query: VersionPublishQuery) => {
  return request.post({
    url: '/app/publish',
    data: query,
    headersType: 'multipart/form-data'
  })
}

// 应用资料同步
export const AppSyncApi = (appId: string) => {
  return request.post({
    url: '/app/sync',
    data: { appId: appId }
  })
}

// 版本详情接口
export const VersionInfoApi = (versionId: string) => {
  return request.get({
    url: '/version',
    params: { versionId: versionId }
  })
}

// 版本apk文件下载
export const ApkDownloadApi = (versionId: string) => {
  return request.get({
    url: '/version/apk',
    params: { versionId: versionId },
    responseType: 'blob'
  })
}

// 同步审核详情
export const SyncCheckInfoApi = (appId: string) => {
  return request.post({
    url: '/app/check/sync',
    params: { appId: appId }
  })
}
